/*
** Text-Based Gaming System 
** Copyright (C) 2008 Eric Day
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to:
** Free Software Foundation, Inc.
** 51 Franklin Street, Fifth Floor,
** Boston, MA  02110-1301, USA
*/

#ifndef _TGS_H
#define _TGS_H

#include "tgs_common.h"

#include "tui.h"

typedef struct _TGS           TGS;
typedef struct _TGS_GAME      TGS_GAME;
typedef struct _TGS_GAME_LIST TGS_GAME_LIST;

/* some contstants and defaults */
#define TGS_DEFAULT_SERVER      "localhost"
#define TGS_PROMPT              "tgs> "
#define TGS_PROMPT_NAME         "Please Enter Your Name> "
#define TGS_DEFAULT_GAME_STATUS "No Game Currently In Play"
#define TGS_GAME_WIN_HEIGHT     16

/* macros to help with error checking */
#define TGS_RET_CHECK(__tgs, __check, __func, __errno) { \
    if (__check) \
    { \
        tui_destroy((__tgs)->tui); \
        if (__errno > 0) \
        { \
            fprintf(stderr, __func ":%d:%s\n", __errno, strerror(__errno)); \
            return __errno; \
        } \
        fprintf(stderr, __func ":%d\n", __errno); \
        return -1; \
    } }

#define TGS_TOK_CHECK(__tgs, __tok, __msg) { \
    if ((__tok) == NULL) \
    { \
        int ret = tui_scroll_printf((__tgs)->tui, "*** %s", __msg); \
        TGS_RET_CHECK(__tgs, ret, "tui_scroll_printf", ret); \
        return 0; \
    } }

/* global variables */
extern TGS_GAME tgs_draw;
extern TGS_GAME tgs_sudoku;

/*
** structs
*/

struct _TGS
{
    LPC      *lpc;
    TUI      *tui;
    char      status[TGS_STR_LEN];
    char      name[TGS_NAME_LEN];
    int       last_act;
    TGS_GAME *game;
    void     *game_data;
    WINDOW   *game_win;
};

struct _TGS_GAME
{
    char  *name;
    int  (*start)(TGS *tgs);
    int  (*part)(TGS *tgs);
    int  (*input)(TUI *tui, void *data, int key);
    int  (*focus)(TUI *tui, void *data);
    int  (*data)(TGS *tgs, char *buf);
};

#endif /* _TGS_H */
